package com.blog.applet.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.applet.domain.BlogArticles;
import com.blog.applet.mapper.BlogArticlesMapper;
import com.blog.applet.service.BlogArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/***
 * @Author 鳄鱼杆
 * @Date 2025/5/20 14:40
 */
@Service
public class BlogArticlesServiceImpl extends ServiceImpl<BlogArticlesMapper, BlogArticles> implements BlogArticlesService {


    @Autowired
    private BlogArticlesMapper blogArticlesMapper;
    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @Override
    public Page<BlogArticles> selectPage(Integer pageNum, Integer pageSize, Long categoryId) {

        // 创建分页对象，第一页，每页5条数据
        Page<BlogArticles> page = new Page<>(pageNum, pageSize);

        // 创建查询条件
        LambdaQueryWrapper<BlogArticles> queryWrapper = new LambdaQueryWrapper<>();
        //如果categoryId不为空，则查询指定分类下的文章
        queryWrapper.eq(categoryId != null, BlogArticles::getCategoryId, categoryId);

        // 执行分页查询
        return blogArticlesMapper.selectPage(page, queryWrapper);
    }
}
